package com.jxt.myjxtmanager.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.jxt.myjxtmanager.R;
import com.jxt.myjxtmanager.entity.AskForLeaveBean;

import java.util.List;

/**
 * Created by qm on 2017/3/13 0013.
 */
public class GalleryAdapter extends
        RecyclerView.Adapter<GalleryAdapter.ViewHolder> {
    private LayoutInflater mInflater;
    private List<AskForLeaveBean> mItemDatas;
    private OnItemClackLisenter onItemClackLisenter;

    public GalleryAdapter(Context context, List<AskForLeaveBean> datats, OnItemClackLisenter onItemClackLisenter) {
        mInflater = LayoutInflater.from(context);
        mItemDatas = datats;
        this.onItemClackLisenter = onItemClackLisenter;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public ViewHolder(View arg0) {
            super(arg0);
        }

        TextView tv_leave_content;
        TextView tv_leave_time;
        Button btn_leave_cancle;
        Button btn_leave_sure;
        TextView tv_leave_title;
    }

    @Override
    public int getItemCount() {
        return mItemDatas.size();
    }

    /**
     * 创建ViewHolder
     */
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, final int i) {
        View view = mInflater.inflate(R.layout.item_answer_leave,
                viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.tv_leave_content = (TextView) view.findViewById(R.id.tv_leave_content);
        viewHolder.tv_leave_time = (TextView) view.findViewById(R.id.tv_leave_time);
        viewHolder.btn_leave_cancle = (Button) view.findViewById(R.id.btn_leave_cancle);
        viewHolder.btn_leave_sure = (Button) view.findViewById(R.id.btn_leave_sure);
        viewHolder.tv_leave_title = (TextView) view.findViewById(R.id.tv_leave_title);

        viewHolder.btn_leave_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClackLisenter != null) {
                    onItemClackLisenter.onCancle(i);
                }
            }
        });
        viewHolder.btn_leave_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClackLisenter != null) {
                    onItemClackLisenter.onSure(i);
                }
            }
        });
        return viewHolder;
    }

    /**
     * 设置值
     */
    @Override
    public void onBindViewHolder(final ViewHolder viewHolder, final int i) {
        viewHolder.tv_leave_content.setText("请假原因： " + mItemDatas.get(i).getLeaveReason());
        viewHolder.tv_leave_time.setText("开始时间： " + mItemDatas.get(i).getLeaveTime() + "\n请假时长： " + mItemDatas.get(i).getLeaveHowLong() + "天");
        viewHolder.tv_leave_title.setText("请假人： " + mItemDatas.get(i).getName());
    }

    public interface OnItemClackLisenter {
        void onCancle(int position);

        void onSure(int position);
    }

}